package main

import (
	"encoding/json"
	"fmt"
	"net/http"
)

// point 存储积分值
var point int

// 处理获取 point 值的请求
func getPointHandler(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json")
	json.NewEncoder(w).Encode(map[string]int{"point": point})
}

// 处理增加 point 值的请求
func incrementPointHandler(w http.ResponseWriter, r *http.Request) {
	point++
	w.Header().Set("Content-Type", "application/json")
	json.NewEncoder(w).Encode(map[string]int{"point": point})
}

// 提供 HTML 页面
func indexHandler(w http.ResponseWriter, r *http.Request) {
	http.ServeFile(w, r, "index.html")
}

func main() {
	http.HandleFunc("/", indexHandler)
	http.HandleFunc("/getPoint", getPointHandler)
	http.HandleFunc("/incrementPoint", incrementPointHandler)

	fmt.Println("Server started at :8080")
	if err := http.ListenAndServe(":8080", nil); err != nil {
		fmt.Println("Server error:", err)
	}
}
